package com.example.todotask.database;

import java.util.List;

import android.database.Cursor;

import com.example.todotask.model.Task;
import com.example.todotask.model.TaskDao;

public class TaskHandler {
	private TaskDao taskDao;

	public TaskHandler(TaskDao taskDao) {
		this.taskDao = taskDao;
	}
	
	/**
	 * Xoa task
	 * @param task
	 */
	public void delete(Task task) {
		if (task != null) {
			taskDao.delete(task);
		}
	}
	
	/**
	 * Cap nhat thong tin chi tiet mot task
	 * @param task
	 */
	public void update(Task task) {
		if (task != null) {
			taskDao.update(task);
		}
	}
	
	/**
	 * Them moi mot task
	 * @param task
	 * @return
	 */
	public long insert(Task task) {
		if (task != null) {
			long result = taskDao.insert(task);
			return result;
		}
		
		return -1L;
	}
	
	/**
	 * Lay thong tin chi tiet mot task
	 * @param key
	 * @return
	 */
	public Task loadTask(long key) {
		return taskDao.loadByRowId(key);
	}
	
	/**
	 * Lay tat ca ca task
	 * @return
	 */
	public List<Task> loadAllTask() {
		return taskDao.loadAll();
	}
}
